package com.wifi.a007.wifiFragment;

import android.content.DialogInterface;

import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.wifi.a007.R;

import java.util.List;

/**
 * Created by Administrator on 2017/6/29.
 */

public class wifiAdapter extends RecyclerView.Adapter<wifiAdapter.ViewHolder> {



    private List<HotInfo> wifiList;

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView wifiImage;
        TextView  wifiName;
        View wifiView;
        Button wifiContent;

        public ViewHolder(View view){


            super(view);
            wifiView = view;
            wifiImage=(ImageView)view.findViewById(R.id.wifi_image);
            wifiName =(TextView)view.findViewById(R.id.wifi_name);
            wifiContent=(Button)view.findViewById(R.id.wifi_content);

        }




    }

    public wifiAdapter(List<HotInfo> wifiList) {
        this.wifiList = wifiList;
    }

    @Override
    public wifiAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.wifi_layout,parent,false);
        final ViewHolder holder = new ViewHolder(view);



        holder.wifiContent.setOnClickListener(new View.OnClickListener(){


            @Override
            public void onClick(View view) {
                int position = holder.getAdapterPosition();
                HotInfo hotInfo= wifiList.get(position);
                alertDialog(hotInfo,view);

            }
        });


        return holder;
    }

    private  void alertDialog(HotInfo hotInfo, View view){

        String content="热点名称: "+hotInfo.getBSSID()+"\n信号强度: "+hotInfo.getLevel()+"  \n信道: "+hotInfo.getChannel()+"\n频率: "+hotInfo.getFrequency()+"\n加密方式:"+hotInfo.getCapabilities();

        AlertDialog.Builder dialog=new AlertDialog.Builder(view.getContext());
        dialog.setTitle("wifi InfoMation");
        dialog.setMessage(content);
        // dialog.setCancelable(true);
       /* dialog.setNegativeButton("cancle",new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

                Log.i("cancle","good boy");

            }

        });*/


        dialog.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {


            }
        });
        dialog.show();

    }




    @Override
    public void onBindViewHolder(wifiAdapter.ViewHolder holder, int position) {
        HotInfo hotInfo=wifiList.get(position);
        holder.wifiImage.setImageResource(hotInfo.getImageResource());

        String wifiResult=new String();
        wifiResult=hotInfo.getSSID();
        holder.wifiName.setText(wifiResult);
    }


    @Override
    public int getItemCount() {
        return wifiList.size();
    }



}
